package com.macro.mall.portal.service.impl;

import com.macro.mall.mapper.UmsMemberReceiveAddressMapper;
import com.macro.mall.model.Addr;
import com.macro.mall.model.UmsMemberReceiveAddress;
import com.macro.mall.model.UmsMemberReceiveAddressExample;
import com.macro.mall.portal.service.AddressService;
import com.macro.mall.portal.util.AddressParse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @Author：尚志豪
 * @Package：com.macro.mall.portal.service.impl
 * @Project：mall-swarm-B
 * @name：AddressServiceImpl
 * @Date：2024/10/31 11:32
 */
@Service
public class AddressServiceImpl implements AddressService {

    @Autowired
    private UmsMemberReceiveAddressMapper umsMemberReceiveAddressMapper;

    @Autowired
    private AddressParse addressParse;
    /**
     * 地址列表
     */
    @Override
    public List<UmsMemberReceiveAddress> list() {
        return umsMemberReceiveAddressMapper.selectByExample(new UmsMemberReceiveAddressExample());
    }
    /**
     * 解析字符串为收货地址
     */
    @Override
    public UmsMemberReceiveAddress string2Addr(Addr addr) {
        return addressParse.parse(addr.getAddr());
    }
    /**
     * 添加
     */
    @Override
    public void add(UmsMemberReceiveAddress umsMemberReceiveAddress) {
        umsMemberReceiveAddressMapper.insert(umsMemberReceiveAddress);
    }
    /**
     * 根据id回显
     */
    @Override
    public UmsMemberReceiveAddress find(Integer id) {
        return umsMemberReceiveAddressMapper.selectByPrimaryKey(Long.valueOf(id));
    }
    /**
     * 修改
     */
    @Override
    public void update(UmsMemberReceiveAddress umsMemberReceiveAddress) {
        umsMemberReceiveAddressMapper.updateByPrimaryKeySelective(umsMemberReceiveAddress);
    }
    /**
     * 删除
     */
    @Override
    public void delete(Integer id) {
        umsMemberReceiveAddressMapper.deleteByPrimaryKey(Long.valueOf(id));
    }
}
